import random
from faker import Faker
from app import db
from app.models import Categorys
from sqlalchemy.exc import IntegrityError


fake = Faker()


def fake_categorys(count=10):
    category = Categorys(name='默认分类', sort=0)
    db.session.add(category)
    for i in range(count):
        category = Categorys(name=fake.word(), sort=i)
        db.session.add(category)
        try:
            db.session.commit()
        except IntegrityError:
            db.session.rollback()


